def delete(y):
    flag = 0
    for d in range(2, y):
        if y%d == 0:
            flag = 1
            break
    if flag == 0:
        return y
    else:
        return 0

x = int(input(""))

if x < 10000 and x > 999:
    y = str(x)
    a = int(y[0]+y[1])
    b = int(y[1]+y[2])
    c = int(y[2]+y[3])
    d = int(y[0]+y[1]+y[2])
    e = int(y[1]+y[2]+y[3])
    f = int(y[0])
    g = int(y[1])
    h = int(y[2])
    i = int(y[3])
    j = int(y[0]+y[1]+y[2]+y[3])

    z = []
    z.append(delete(a))
    z.append(delete(b))
    z.append(delete(c))
    z.append(delete(d))
    z.append(delete(e))
    z.append(delete(f))
    z.append(delete(g))
    z.append(delete(h))
    z.append(delete(i))
    z.append(delete(j))
    print(max(z))
else:
    print("0")

